home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk.zip / BI_VARS.C < prev    next >
C/C++ Source or Header  |  1991-04-07  |  2KB  |  88 lines

  1.  
  2. /********************************************
  3. bi_vars.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the Awk programming language as defined in
  8. Aho, Kernighan and Weinberger, The AWK Programming Language,
  9. Addison-Wesley, 1988.
  10.  
  11. See the accompaning file, LIMITATIONS, for restrictions
  12. regarding modification and redistribution of this
  13. program in source or binary form.
  14. ********************************************/
  15.  
  16. /* $Log:    bi_vars.c,v $
  17.  * Revision 2.1  91/04/08  08:22:22  brennan
  18.  * VERSION 0.97
  19.  * 
  20. */
  21.  
  22.  
  23. /* bi_vars.c */
  24.  
  25. #include "mawk.h"
  26. #include "symtype.h"
  27. #include "bi_vars.h"
  28. #include "field.h"
  29. #include "init.h"
  30. #include "memory.h"
  31.  
  32. /* the builtin variables */
  33. CELL  bi_vars[NUM_BI_VAR] ;
  34.  
  35. /* the order here must match the order in bi_vars.h */
  36.  
  37. static char *bi_var_names[NUM_BI_VAR] = {
  38. "ARGC" ,
  39. "FILENAME" ,
  40. "NR" ,
  41. "FNR" ,
  42. "OFS" ,
  43. "ORS" ,
  44. "RLENGTH" ,
  45. "RSTART" ,
  46. "SUBSEP",
  47. "VERSION"
  48. } ;
  49.  
  50. /* insert the builtin vars in the hash table */
  51.  
  52. void  bi_vars_init()
  53. { register int i ;
  54.   register SYMTAB *s ;
  55.  
  56.   for ( i = 0 ; i < NUM_BI_VAR ; i++ )
  57.   { s = insert( bi_var_names[i] ) ;
  58.     s->type = ST_VAR ; s->stval.cp = bi_vars + i ;
  59.     /* bi_vars[i].type = 0 which is C_NOINIT */
  60.   }
  61.   /* set defaults */
  62.  
  63.   bi_vars[FILENAME].type = C_STRING ;
  64.   bi_vars[FILENAME].ptr = (PTR) new_STRING( "" ) ; 
  65.  
  66.   bi_vars[ OFS ].type = C_STRING ;
  67.   bi_vars[OFS].ptr = (PTR) new_STRING( " " ) ;
  68.   
  69.   bi_vars[ ORS ].type = C_STRING ;
  70.   bi_vars[ORS].ptr = (PTR) new_STRING( "\n" ) ;
  71.  
  72.   bi_vars[ SUBSEP ].type = C_STRING ;
  73.   bi_vars[SUBSEP].ptr =  (PTR) new_STRING( "\034" ) ;
  74.  
  75.   bi_vars[VERSION].type = C_STRING ;
  76.   bi_vars[VERSION].ptr = (PTR) new_STRING( VERSION_STRING ) ;
  77.  
  78.   bi_vars[NR].type = bi_vars[FNR].type = C_DOUBLE ;
  79.   /* dval is already 0.0 */
  80.  
  81.   cell_zero.type = C_DOUBLE ;
  82.   cell_one.type = C_DOUBLE ;
  83.   cell_one.dval = 1.0 ;
  84. }
  85.  
  86. CELL cell_zero ;
  87. CELL cell_one ;
  88.